/**
 * 
 */
package com.elephantgreen.xml;

import java.util.Date;
import java.util.Vector;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.elephantgreen.common.Client;
import com.elephantgreen.common.ElephantgreenCommon;
import com.elephantgreen.common.ExisitingSalesData;
import com.elephantgreen.util.Util;

/**
 * @author ABC
 *
 */
public class ExisitingSalesDataXml extends ElephantgreenXmlHandler {

	/**
	 * @param fName
	 * @param parentNodeName
	 */
	public ExisitingSalesDataXml(String fName, String parentNodeName) {
		super(fName, parentNodeName);

	}

	/* (non-Javadoc)
	 * @see com.elephantgreen.persistance.ElephantgreenXmlHandler#getItems()
	 */
	@Override
	public Vector<ElephantgreenCommon> getItems() {

		Vector<ElephantgreenCommon> vExsd = new Vector<ElephantgreenCommon>();

		for (int temp = 0; temp < getNodes().getLength(); temp++) {

			Node nNode = getNodes().item(temp);
			if (nNode.getNodeType() == Node.ELEMENT_NODE) {

				Element element = (Element) nNode;							
				
				Client c = new Client();
				c.setClientId(Util.getTagValue("clientId", element));
				
				ExisitingSalesData exsd = null;
				exsd =	new ExisitingSalesData(

						Util.getTagValue("invoiceNumber", element), 
						c, 
						new Date(Util.getTagValue("saleDate", element)), 
						Double.parseDouble(Util.getTagValue("cashDiscount", element)), 
						Integer.parseInt(Util.getTagValue("percentDiscount", element)),
						Double.parseDouble(Util.getTagValue("saleTotal", element)), 
						Double.parseDouble(Util.getTagValue("finalSaleAmount", element)), 
						Util.getTagValue("adjustmentReason", element), 
						Double.parseDouble(Util.getTagValue("adjustmentAmount", element)), 
						Util.getTagValue("comments", element));
				
				

				vExsd.add(exsd);

			}
		}
		return vExsd;
	}

}

